bits 32
[section .text]
global print
global dwDispPos
global bDispColor
global sys_print

;void * memcpy(void *dst, void* src, int size);
memcpy:
	push	ebp
	mov	ebp, esp
	push	esi
	push	edi
	push	ecx
	mov	edi, [ebp+8]
	mov	esi, [ebp+12]
	mov	ecx, [ebp+16]
	cld
	rep	movsb
	pop	ecx
	pop	edi
	pop	esi
	mov	esp, ebp
	pop	ebp
	ret
	

;void print(char* str);
print:
	push	ebp
	mov	ebp, esp
	push	ebx
	push	esi
	push	edi
	mov	esi, [ebp+8]
	xor	edi, edi
	mov	edi, [dwDispPos]
	mov	ah,  [bDispColor]
.1:
	lodsb
	test	al, al
	jz	.2
	cmp	al, 0Ah
	jnz	.3
	add	edi, 160
	jmp	.1
.3
	cmp	al, 0dh
	jnz	.4
	push	eax
	mov	eax, edi
	mov	bl, 160
	div	bl
	and	eax, 0ffh
	mul	bl
	mov	edi, eax
	pop	eax
	jmp	.1
.4:
	mov	[gs:edi], ax
	add	edi, 2
	jmp	.1
.2:
	mov	[dwDispPos], edi
	pop	edi
	pop	esi
	pop	ebx
	pop	ebp
	ret	

;void sys_print(char* str);
sys_print:
	push	ebp
	mov	ebp, esp
	push	ebx
	push	esi
	push	edi
	mov	esi, [ebp+8]
	xor	edi, edi
	mov	edi, [dwDispPos]
	mov	ah,  [bDispColor]
.1:
	mov	al, [fs:esi]
	inc	esi
	test	al, al
	jz	.2
	cmp	al, 0Ah
	jnz	.3
	add	edi, 160
	jmp	.1
.3
	cmp	al, 0dh
	jnz	.4
	push	eax
	mov	eax, edi
	mov	bl, 160
	div	bl
	and	eax, 0ffh
	mul	bl
	mov	edi, eax
	pop	eax
	jmp	.1
.4:
	mov	[gs:edi], ax
	add	edi, 2
	jmp	.1
.2:
	mov	[dwDispPos], edi
	pop	edi
	pop	esi
	pop	ebx
	pop	ebp
	ret	
[SECTION .data]
ALIGN 32	
dwDispPos dd 0
bDispColor db 0x0f

